#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Maxn=1e5+7;
const ll inf=1e12;
int n;
struct node{
    int a,b;
}a[Maxn];

ll ans=inf;
ll min1=inf,min2=inf;

int main(){
    freopen("boast.in","r",stdin);
    freopen("boast.out","w",stdout);

    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&a[i].a,&a[i].b);
    sort(a+1,a+n+1,[](node x,node y){
        return x.b>y.b;
    });
    for(int i=1;i<=n;i++){
        ans=min(ans,a[i].a+min1+min2);
        if(a[i].a+a[i].b==min1) min2=min(min2,1ll*a[i].a+a[i].b);
        if(a[i].a+a[i].b<min1){
            min2=min1;
            min1=a[i].a+a[i].b;
        }
    }
    cout<<ans;

    // system("pause");
    return 0;
}
/*
6
1 1
4 5
1 4
1 9
1 9
8 10
*/